package extreme.refactor.gilded_rose;

class GildedRose {
    Item[] items;

    public GildedRose(Item[] items) {
        this.items = items;
    }

    private int add(int q,int num){
        q += num;
        if(q>50){
            return 50;
        }
        return q;
    }

    private int dev(int q, int num) {
        q -= num;
        if(q<0){
            return 0;
        }
        return q;
    }

    private void doAgedBrie(Item item){
        if(item.sell_in<0){
            item.quality = this.add(item.quality, 2);
        }else{
            item.quality = this.add(item.quality, 1);
        }
    }

    private void doSulfuras(Item item) {

    }

    private void doBackstage(Item item) {
        if(item.sell_in<0){
            item.quality = 0;
        }else if(item.sell_in<5){
            item.quality = this.add(item.quality, 3);
        }else if(item.sell_in<10){
            item.quality = this.add(item.quality, 2);
        }else{
            item.quality = this.add(item.quality, 1);
        }
    }

    private void doNomal(Item item) {
        if(item.sell_in<0){
            item.quality = this.dev(item.quality,2);
        }else{
            item.quality = this.dev(item.quality,1);
        }

    }



    private void makeItem(Item item){

        switch (item.name) {
            case "Aged Brie":
                item.sell_in --;
                this.doAgedBrie(item);
                break;
            case "Sulfuras, Hand of Ragnaros":
                this.doSulfuras(item);
                break;
            case "Backstage passes to a TAFKAL80ETC concert" :
                item.sell_in --;
                this.doBackstage(item);
                break;
            default:
                item.sell_in --;
                this.doNomal(item);
                break;
        }


    }

    public void update_quality() {
        for (int i = 0; i < items.length; i++) {
            this.makeItem(items[i]);
        }
    }
}
